//
//  FestivalViewController.m
//  代号：47
//
//  Created by 杨佩璋 on 15/6/30.
//  Copyright (c) 2015年 杨佩璋. All rights reserved.
//

#import "FestivalViewController.h"
#import "AFNetworking.h"
#import "FestivalTableViewCell.h"
#import "FestivalTableViewCell2.h"
#import "FestivalModel.h"
#import <UIImageView+WebCache.h>
#import "DetailViewController.h"
#import "ChartsViewController.h"
#import "PaiHangViewController.h"
#import <MediaPlayer/MediaPlayer.h>
#import <AVFoundation/AVFoundation.h>
#import "ThreeViewController.h"




@interface FestivalViewController ()<UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate>
{
    MBProgressHUD *hud;
}
@property (nonatomic,retain)NSMutableArray *modelArray; // model 数组。
@property (nonatomic,retain)AFHTTPRequestOperation *operation; // 操作。
@property (nonatomic,retain) NSOperationQueue *queue;  // 操作队列
@property (nonatomic,retain)UITableView *mainTableView; // 主tableView
@property (nonatomic,retain)UIView *clearView;  // 透明View ,用来遮盖
@property (nonatomic,retain)UIScrollView *scroll; // 轮播图
@property (nonatomic,retain)NSMutableDictionary *dic1; // 四张轮播图图片
@property (nonatomic,retain)NSMutableDictionary *dic2; // 四张轮播图图片
@property (nonatomic,retain)NSMutableDictionary *dic3; // 四张轮播图图片
@property (nonatomic,retain)NSMutableDictionary *dic4; // 四张轮播图图片
@property (nonatomic,retain)AFHTTPRequestOperation *operation2; // 操作2。
@property (nonatomic,retain)NSOperationQueue *queue2;  // 操作队列2
@property (nonatomic,retain)NSTimer *timer; // 定时器
@property (nonatomic,retain)UIPageControl *pageControl; //

// 测试 手势
@property (nonatomic,retain)UIImageView *imageView0; //
@property (nonatomic,retain)UIImageView *imageView1; //
@property (nonatomic,retain)UIImageView *imageView2; //
@property (nonatomic,retain)UIImageView *imageView3; //
@property (nonatomic,retain)UIImageView *imageView4; //


@property (nonatomic,retain)MPMoviePlayerViewController *movewController;


@property (nonatomic,retain) NSNumber *pageIndex; // 加载的页面








@end

@implementation FestivalViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"美好时光";
    self.view.backgroundColor = [UIColor whiteColor];
    [self createdownLoadProgress];
    // 先创建好
    [self lauyUI];
    [self myInitiall];
    [self requestData];  // 请求数据
    
}


#pragma mark - 初始化数据
- (void)myInitiall{
    self.modelArray = [NSMutableArray array];
    self.dic1 = [NSMutableDictionary dictionary];
    self.dic2 = [NSMutableDictionary dictionary];
    self.dic3 = [NSMutableDictionary dictionary];
    self.dic4 = [NSMutableDictionary dictionary];
}

#pragma mark -  布局
- (void)lauyUI{
    [self createTableView];   // 创建tableView
    [self createScrollerView];
    [self createPageControl];
    // [self createTimer]; // 开启定时器
    // 添加左上角 抽屉按钮
    UIImage *image = [UIImage imageNamed:@"iconfont-guanli"];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button addTarget:self action:@selector(drawer) forControlEvents:UIControlEventTouchUpInside];
    [button setBackgroundImage:image forState:UIControlStateNormal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    button.width = 30;
    button.height = 30;
    
    [self addUpRefresh];
}




#pragma mark - 懒加载 页面
-(NSNumber *)pageIndex{
    if (!_pageIndex) {
        _pageIndex = [NSNumber numberWithInteger:1];
    }
    return _pageIndex;
}


//  抽屉按钮 调用方法
- (void)drawer
{
    
    
    CGRect new = self.tabBarController.view.frame;
    if (new.origin.x == 0) {
        [UIView animateWithDuration:0.3 animations:^{
            self.tabBarController.view.x = 0.7*kScreen_width;
            self.tabBarController.view.y = (kScreen_height-kScreen_height *0.7)/2;
            self.tabBarController.view.height = kScreen_height *0.7;
            
        } completion:^(BOOL finished) {
            [self createClearView];
            [self.mydelegate show];
        }];
    }else
    {
        [self.mydelegate dismiss];
        [UIView animateWithDuration:0.3 animations:^{
            self.tabBarController.view.x = 0;
            self.tabBarController.view.y = 0;
            self.tabBarController.view.height = kScreen_height;
        } completion:^(BOOL finished) {
            [self removeClearView];
            
        }];
    }
}



// 加载进度条
- (void)createdownLoadProgress{
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    hud = [[MBProgressHUD alloc] initWithView:self.view];
    hud.color = [UIColor grayColor];
    [self.view addSubview:hud];
    hud.labelText = @"努力加载中..";
    //设置模式为环状进度提示框
    [hud show:YES];
    [hud release];
}





// 创建遮盖
- (void)createClearView
{
    _clearView = [[UIView alloc] initWithFrame:kScreen_Frame];
    [self.tabBarController.view addSubview:self.clearView];
    [_clearView release];
    
    // 添加点击手势
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(drawer)];
    [self.clearView addGestureRecognizer:tapGesture];
    [tapGesture release];
    
}


// 移除遮盖
- (void)removeClearView
{
    [self.clearView  removeFromSuperview];
}




- (void)createTableView
{
    _mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreen_width, kScreen_height - 48) style:UITableViewStylePlain];
    [_mainTableView registerClass:[FestivalTableViewCell class] forCellReuseIdentifier:@"festcell"];
    [_mainTableView registerClass:[FestivalTableViewCell2 class] forCellReuseIdentifier:@"festcell2"];
    _mainTableView.delegate = self;
    _mainTableView.dataSource = self;
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.modelArray.count;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    FestivalModel *model = [self.modelArray objectAtIndex:indexPath.row];
    if (model.images.count  >1) {
        return 200;
        
    }else{
        return 115;
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    FestivalModel *model = [self.modelArray objectAtIndex:indexPath.row];
    if (model.images.count > 1) {
        FestivalTableViewCell2 *cell = [tableView dequeueReusableCellWithIdentifier:@"festcell2" forIndexPath:indexPath];
        cell.model = model;
        return cell;
    }else{
        
        
        FestivalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"festcell" forIndexPath:indexPath];
        cell.model = model;
        return cell;
        
    }
}


// AFN 数据请求
- (void)requestData
{
    NSString *str = [NSString stringWithFormat:@"http://api.m.mtime.cn/News/NewsList.api?pageIndex=%@",self.pageIndex];
    NSURL *url = [NSURL URLWithString:str];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    self.operation = operation;
    [operation release];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSString *html = operation.responseString;
        NSData* data=[html dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers|NSJSONReadingMutableLeaves error:nil];
        NSArray *array = dic[@"newsList"];
        for (NSDictionary *dic in array) {
            FestivalModel *model = [[FestivalModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [self.modelArray addObject:model];
            [model release];
        }
        
        [hud hide:YES];
        [hud removeFromSuperview];
        [self.view addSubview:_mainTableView];
        _mainTableView.tableHeaderView = self.scroll;
        [self.mainTableView addSubview:_pageControl];
        [_pageControl release];
        
        [self.mainTableView.defaultHeader endRefreshing];
        [self.mainTableView.defaultFooter endRefreshing];
        [self.mainTableView reloadData];
        [self requestData2];
        
    } failure:nil];
    
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    [queue addOperation:operation];
    self.queue = queue;
    [queue release];
}


- (void)createScrollerView{
    _scroll = [[UIScrollView alloc] initWithFrame: CGRectMake(0, 0, kScreen_width, kScreen_width*320/640)];
    self.scroll.contentSize = CGSizeMake(kScreen_width *5, kScreen_width*320/640);
    //    _mainTableView.tableHeaderView = scroll;
    self.scroll.pagingEnabled = YES;
    self.scroll.delegate = self;
}


-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
}

// 监听方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    NSInteger index = self.scroll.contentOffset.x / kScreen_width;
    self.pageControl.currentPage =  index;
    if (self.scroll.contentOffset.x == 4 *kScreen_width) {
        self.pageControl.currentPage = 0;
    }
    if (self.scroll.contentOffset.x > 4 *kScreen_width) {
        self.scroll.contentOffset = CGPointMake(0, 0);
    }
    if (self.scroll.contentOffset.x < 0) {
        self.scroll.contentOffset = CGPointMake(4 *kScreen_width, 0);
    }
}


- (void)slide{
    CGFloat nowX = self.scroll.contentOffset.x;
    CGFloat nowY = self.scroll.contentOffset.y;
    nowX += kScreen_width;
    [self.scroll setContentOffset:CGPointMake(nowX, nowY) animated:YES];
    if (nowX >4 *kScreen_width) {
        self.scroll.contentOffset = CGPointMake(0, 0);
    }
}


// 触摸关闭定时
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    [self stopTimer];
}


// 开启定时
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
    [self createTimer];
}


// 创建定时器
- (void)createTimer{
    _timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(slide) userInfo:nil repeats:YES];
}


// 关闭定时器
- (void)stopTimer{
    [_timer invalidate];
}





// 创建pageControl
- (void)createPageControl{
    _pageControl = [[UIPageControl alloc] init];
    self.pageControl.size = CGSizeMake(100, 20);
    self.pageControl.centerX = self.mainTableView.centerX;
    self.pageControl.y = 0;
    _pageControl.pageIndicatorTintColor = [UIColor grayColor];
    _pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
    _pageControl.numberOfPages = 4;
    _pageControl.currentPage = 0;
}


// 请求轮播图数据
- (void)requestData2
{
    [self stopTimer];
    NSURL *url = [NSURL URLWithString:@"http://api.m.mtime.cn/PageSubArea/GetRecommendationIndexInfo.api"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    self.operation2 = operation;
    [operation release];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSString *html = operation.responseString;
        NSData* data=[html dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers|NSJSONReadingMutableLeaves error:nil];
        NSDictionary *dic1 = dic[@"news"];
        NSDictionary *dic2 = dic[@"review"];
        NSDictionary *dic3 = dic[@"topList"];
        NSDictionary *dic4 = dic[@"trailer"];
        self.dic1 = [NSMutableDictionary dictionaryWithDictionary:dic1];
        self.dic2 = [NSMutableDictionary dictionaryWithDictionary:dic2];
        self.dic3 = [NSMutableDictionary dictionaryWithDictionary:dic3];
        self.dic4 = [NSMutableDictionary dictionaryWithDictionary:dic4];
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        [self createFour];
        [self createTimer];
    } failure:nil];
    
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    [queue addOperation:operation];
    self.queue2 = queue;
    [queue release];
}



// 创建轮播图
- (void)createFour{
    [self createImageView:self.dic1 index:0 imageView:self.imageView0 andTag:100];
    [self createImageView:self.dic2 index:1 imageView:self.imageView1 andTag:101];
    [self createImageView:self.dic3 index:2 imageView:self.imageView2 andTag:102];
    [self createImageView:self.dic4 index:3 imageView:self.imageView3 andTag:103];
    // 障眼法图片
    [self createImageView:self.dic1 index:4 imageView:self.imageView4 andTag:104];
}

// 传一个字典进来 返回一张图片
- (void)createImageView:(NSDictionary *)dic index:(NSInteger)index imageView:(UIImageView *)imageView andTag:(NSInteger)tagNumber{
    CGFloat kw = kScreen_width;
    CGFloat kh = kScreen_width*320/640;
    imageView = [[UIImageView alloc] initWithFrame:CGRectMake(index *kScreen_width, 0, kw,  kh)];
    imageView.tag = tagNumber;
    imageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(afangfa:)];
    
    [imageView addGestureRecognizer:tap];
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    // 一共三种情况
    NSString *imageUrl = dic[@"imageUrl"];
    // NSString *title = dic[@"title"];
    [imageView sd_setImageWithURL:[NSURL URLWithString:imageUrl]];
    [self.scroll addSubview:imageView];
    
    if (dic[@"posterUrl"]) {
        NSString *posterUrl = dic[@"posterUrl"];
        CGFloat small = 0.3 *kh;
        UIView *smallView = [[UIView alloc] initWithFrame:CGRectMake(0, kh - small, kScreen_width, small)];
        smallView.backgroundColor = RGBColor(12, 67, 91);
        [imageView addSubview:smallView];
        CGFloat postw = 1.0/6 *kScreen_width;
        CGFloat posth = postw *1271/900;
        UIImageView *post = [[UIImageView alloc] initWithFrame:CGRectMake(20, kh - 10-posth, postw, posth)];
        [post sd_setImageWithURL:[NSURL URLWithString:posterUrl]];
        [imageView addSubview:post];
        [post release];
        CGFloat movieX = 20 + postw + 20;
        UILabel *movieName = [[UILabel alloc] initWithFrame:CGRectMake(movieX, 0.2*small, kScreen_width - movieX, 0.4*small)];
        movieName.text = dic[@"movieName"];
        movieName.font = [UIFont boldSystemFontOfSize:16];
        movieName.textColor = [UIColor whiteColor];
        movieName.textAlignment = NSTextAlignmentLeft;
        [smallView addSubview:movieName];
        [movieName release];
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(movieX, 0.6*small, kScreen_width - movieX, 0.4*small)];
        title.text = [NSString stringWithFormat:@"“%@",dic[@"title"]];
        title.textColor = RGBColor(178, 189, 194);
        title.font = [UIFont systemFontOfSize:12];
        [smallView addSubview:title];
        [smallView release];
        [title release];
    }else if (dic[@"mp4Url"]){
        //  NSString *mp4Url = dic[@"mp4Url"];
        CGFloat small = 0.2 *kh;
        UIView *smallView = [[UIView alloc] initWithFrame:CGRectMake(0, kh - small, kScreen_width, small)];
        smallView.backgroundColor = RGBColor(39, 41, 33);
        smallView.alpha = 0.95;
        [imageView addSubview:smallView];
        UILabel *title = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, kScreen_width - 30, small)];
        title.text = dic[@"title"];
        title.font = [UIFont boldSystemFontOfSize:16];
        title.textColor = [UIColor whiteColor];
        title.textAlignment = NSTextAlignmentCenter;
        [smallView addSubview:title];
        UIImageView *play = [[UIImageView alloc] initWithFrame:CGRectMake(kScreen_width - small - 20, 0, small, small)];
        play.image = [UIImage imageNamed:@"iconfont-bofang(2)"];
        [smallView addSubview:play];
        [play release];
        [title release];
        [smallView release];
    }else{
        CGFloat small = 0.2 *kh;
        UIView *smallView = [[UIView alloc] initWithFrame:CGRectMake(0, kh - small, kScreen_width, small)];
        smallView.backgroundColor = RGBColor(39, 41, 33);
        smallView.alpha = 0.95;
        [imageView addSubview:smallView];
        UILabel *title = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, kScreen_width , small)];
        title.text = dic[@"title"];
        title.font = [UIFont boldSystemFontOfSize:16];
        title.textColor = [UIColor whiteColor];
        title.textAlignment = NSTextAlignmentCenter;
        [smallView addSubview:title];
        [smallView release];
        [title release];
    }
    
    
    [imageView release];
    
}


#pragma mark - 轮播图选择
- (void)afangfa:(UIGestureRecognizer *)gest{
    UIImageView *imageView = (UIImageView *)(gest.view);
    
    switch (imageView.tag) {
        case 100:
        case 104:
        {
            DetailViewController *deVC = [[DetailViewController alloc] init];
            deVC.mytitle = self.dic1[@"title"];
            deVC.newsId = self.dic1[@"newsID"];
            [self.navigationController pushViewController:deVC animated:YES];
            [deVC release];
        }
            break;
        case 101:
        {
            ChartsViewController *chVC = [[ChartsViewController alloc] init];
            NSNumber *number = self.dic2[@"reviewID"];
            chVC.reviewId = number;
            [self.navigationController pushViewController:chVC animated:YES];
            [chVC release];
            break;
        }
        case 102:
        {
            PaiHangViewController *paiHang = [[PaiHangViewController alloc] init];
            NSNumber *number = self.dic3[@"id"];
            paiHang.list = number;
            [self.navigationController pushViewController:paiHang animated:YES];
            [paiHang release];
            break;
            
        }
        case 103:{
            NSString *str = self.dic4[@"mp4Url"];
            NSString *urlStr =[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            NSURL *movieURL = [NSURL URLWithString:urlStr];
            MPMoviePlayerViewController *myplayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
            [self presentMoviePlayerViewControllerAnimated:myplayer];
            [myplayer release];
            break;
            
        }
        default:
            break;
    }
    
}


#pragma mark  -  选择下面的cell
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    FestivalModel *model = self.modelArray[indexPath.row];
    if (model.images.count > 1) {
        ThreeViewController *threeVC = [[ThreeViewController alloc] init];
        threeVC.newsId = model.ID;
        threeVC.mytitle = model.title;
        [self.navigationController pushViewController:threeVC animated:YES];
        [threeVC release];
        
        
    }else{
        
        
        
        DetailViewController *deVC = [[DetailViewController alloc] init];
        deVC.mytitle = model.title;
        deVC.newsId = model.ID;
        [self.navigationController pushViewController:deVC animated:YES];
        [deVC release];
    }
}




- (void)requestNewData{
    NSString *str = [NSString stringWithFormat:@"http://api.m.mtime.cn/News/NewsList.api?pageIndex=%@",self.pageIndex];
    NSURL *url = [NSURL URLWithString:str];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    self.operation = operation;
    [operation release];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSString *html = operation.responseString;
        NSData* data=[html dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers|NSJSONReadingMutableLeaves error:nil];
        NSArray *array = dic[@"newsList"];
        for (NSDictionary *dic in array) {
            FestivalModel *model = [[FestivalModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [self.modelArray addObject:model];
            [model release];
        }
        [self.mainTableView.defaultHeader endRefreshing];
        [self.mainTableView.defaultFooter endRefreshing];
        [self.mainTableView reloadData];
        
    } failure:nil];
    
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    [queue addOperation:operation];
    self.queue = queue;
    [queue release];
    
}



// 下拉刷新

- (void)requestNewData2{
    NSString *str = [NSString stringWithFormat:@"http://api.m.mtime.cn/News/NewsList.api?pageIndex=%@",self.pageIndex];
    NSURL *url = [NSURL URLWithString:str];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    self.operation = operation;
    [operation release];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        [self.modelArray removeAllObjects];
        NSString *html = operation.responseString;
        NSData* data=[html dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers|NSJSONReadingMutableLeaves error:nil];
        NSArray *array = dic[@"newsList"];
        for (NSDictionary *dic in array) {
            FestivalModel *model = [[FestivalModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [self.modelArray addObject:model];
            [model release];
        }
        [self.mainTableView.defaultHeader endRefreshing];
        [self.mainTableView.defaultFooter endRefreshing];
        [self.mainTableView reloadData];
        
    } failure:nil];
    
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    [queue addOperation:operation];
    self.queue = queue;
    [queue release];
    
}


// 添加上拉加载
-(void)addUpRefresh{
    
    [self.mainTableView addRefreshWithRefreshViewType:LORefreshViewTypeFooterDefault refreshingBlock:^{
        NSInteger number= [self.pageIndex integerValue];
        number++;
        self.pageIndex = [NSNumber numberWithInteger:number];
        [self requestNewData];
    }];
    
    [self.mainTableView addRefreshWithRefreshViewType:LORefreshViewTypeHeaderDefault refreshingBlock:^{
        NSInteger number;
        number = 1;
        self.pageIndex = [NSNumber numberWithInteger:number];
        [self requestNewData2];
        
        for (UIImageView *obj in self.scroll.subviews) {
            [obj removeFromSuperview];
        }
        
        [self requestData2];
        
    }];
    

    
}



-(void)dealloc
{
    [_dic1 release];
    [_dic2 release];
    [_dic3 release];
    [_dic4 release];
    [_operation2 release]; // 操作。
    [_queue2 release];  // 操作队列
    [_scroll release];
    [_mainTableView release];
    [_operation release];
    [_queue release];
    [_modelArray release];
    [super dealloc];
}
@end



